package com.macken.wow.controller;

import javax.servlet.http.HttpServletRequest;

public class BaseController {
	protected static String getIp(HttpServletRequest request) {
		// bell(2011-9): 使用apache模块识别代理，取到的即为真实ip，无需考虑代理中转问题
		//http://zhengjunwei2007.blog.163.com/blog/static/3529794220124921437240/
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		//会出现多个IP 取第二个202.106.180.62, 202.106.180.62
		if (ip != null && ip.indexOf(",") > 0) {
			String ips[] = ip.trim().split(",");
			return ips[ips.length-1].trim();
		}
		return ip;
		//return request.getRemoteAddr();
	}
}
